//普通选择
var setting = {
    edit: {
        enable: true,
        showRemoveBtn: false,
        showRenameBtn: false
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        beforeDrag: beforeDrag,
        beforeDrop: beforeDrop
    }
};
//含复选框
var setting1 = {
    check: {
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    }
};

//可移动
var setting2 = {
    edit: {
        enable: true,
        showRemoveBtn: false,
        showRenameBtn: false
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        beforeDrag: beforeDrag,
        beforeDrop: beforeDrop
    }
};

//虚拟数据
var zNode1 =[
    { id:1, pId:0, name:"一级部门", open:true},
    { id:11, pId:1, name:"二级部门"},
    { id:12, pId:1, name:"二级部门", open:true},
    { id:121, pId:12, name:"三级部门"},
    { id:122, pId:12, name:"三级部门"},
    { id:123, pId:12, name:"三级部门"},
    { id:13, pId:1, name:"二级部门", open:true},
    { id:131, pId:13, name:"三级部门"},
    { id:132, pId:13, name:"三级部门"},
    { id:133, pId:13, name:"三级部门"},
    { id:2, pId:0, name:"一级部门", open:true},
    { id:21, pId:2, name:"二级部门"},
    { id:22, pId:2, name:"二级部门", open:true},
    { id:221, pId:22, name:"三级部门"},
    { id:222, pId:22, name:"三级部门"},
    { id:223, pId:22, name:"三级部门"},
    { id:23, pId:2, name:"二级部门"}
];
var zNode2=[
    { id:1, pId:0, name:"一级部门", open:true},
    { id:2, pId:0, name:"一级部门", open:true},
    { id:3, pId:0, name:"一级部门", open:true},
    { id:4, pId:0, name:"一级部门", open:true},
    { id:5, pId:0, name:"一级部门", open:true},
    { id:6, pId:0, name:"一级部门", open:true},
    { id:7, pId:0, name:"一级部门", open:true},
    { id:8, pId:0, name:"一级部门", open:true}


]

function beforeDrag(treeId, treeNodes) {
    for (var i=0,l=treeNodes.length; i<l; i++) {
        if (treeNodes[i].drag === false) {
            return false;
        }
    }
    return true;
}
function beforeDrop(treeId, treeNodes, targetNode, moveType) {
    return targetNode ? targetNode.drop !== false : true;
}

function setCheck() {
    var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        isCopy = $("#copy").attr("checked"),
        isMove = $("#move").attr("checked"),
        prev = $("#prev").attr("checked"),
        inner = $("#inner").attr("checked"),
        next = $("#next").attr("checked");
    zTree.setting.edit.drag.isCopy = isCopy;
    zTree.setting.edit.drag.isMove = isMove;
    showCode(1, ['setting.edit.drag.isCopy = ' + isCopy, 'setting.edit.drag.isMove = ' + isMove]);

    zTree.setting.edit.drag.prev = prev;
    zTree.setting.edit.drag.inner = inner;
    zTree.setting.edit.drag.next = next;
    showCode(2, ['setting.edit.drag.prev = ' + prev, 'setting.edit.drag.inner = ' + inner, 'setting.edit.drag.next = ' + next]);
}
function showCode(id, str) {
    var code = $("#code" + id);
    code.empty();
    for (var i=0, l=str.length; i<l; i++) {
        code.append("<li>"+str[i]+"</li>");
    }
}

$(document).ready(function(){
    setCheck();
    $("#copy").bind("change", setCheck);
    $("#move").bind("change", setCheck);
    $("#prev").bind("change", setCheck);
    $("#inner").bind("change", setCheck);
    $("#next").bind("change", setCheck);
});